/*
 * @Author: wei_jt@ecidi.com
 * @Date: 2019-11-28 10:42:58
 * @LastEditors: wei_jt@ecidi.com
 * @LastEditTime: 2021-12-31 15:04:40
 * @Description:  全局配置入口
 */
import VueI18n from 'vue-i18n'
import FawkesLib from 'fawkes-lib' //组件库
import { SvgIcon, ExcelExport, FksWebsocket } from '@/components'
import store from '@/store'
import { I18N } from '@/store/Getter/getterTypes'

import { nodePermission, redirectTo } from '@/permission'
import Directives from '@/directives'
import Filters from '@/filters'
import Decorators from '@/decorators'

import request from '@/utils/request' //axios封装
import { getLangConfig, loadLanguageAsync } from '@/utils/locale'
import { themeInit } from './theme.js'
import { transDate } from './timezone'
import mixin from '@/mixins/default' //全局混入
import storage from './storage'
import settings from '@/config'
import dayjs from 'dayjs'



const plugin = {}
plugin.install = function (Vue) {
  //国际化
  const lang = getLangConfig()
  Vue.prototype.$lang = store.getters.language || lang //默认系统配置语言

  if (store.getters[I18N]) {
    //国际化开启
    Vue.use(VueI18n)
    loadLanguageAsync(lang)
  }
  Vue.mixin(mixin)



  !Vue.prototype.$InQianKun && import('fawkes-lib/lib/theme-chalk/index.css').then(() => {
    themeInit()
  })



  Vue.component('svg-icon', SvgIcon) //在线svg组件注册，本地模块可改为离线svg组件
  Vue.component('excel-export', ExcelExport)

  //svg载入

  const req = require.context('@/assets/svg', true, /\.svg$/)
  const requireAll = (requireContext) =>
    requireContext.keys().map(requireContext)
  requireAll(req)

  Vue.use(Directives)
  Vue.use(Filters)
  Vue.use(Decorators)

  Vue.prototype.$FksWebsocket = FksWebsocket
  Vue.prototype.$axios = request
  Vue.prototype.nodePermission = nodePermission
  Vue.prototype.redirectTo = redirectTo

  Vue.prototype.$storage = storage
  Vue.prototype.$transDate = transDate

  //fawkes组件库
  Vue.use(FawkesLib, {
    preciseSearch: true,
    hideSwitch: true
  })
}
export default plugin
